﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.display.*;
    import flash.text.*;

    public class ContextMenuItem extends Sprite {

        public static const STATE_UP:String = "up";
        public static const STATE_OVER:String = "over";

        protected var m_state:String;
        protected var m_label:String;
        protected var m_action:String;
        protected var m_bgShape:Shape;
        protected var m_textField:TextField;
        protected var m_style:Object;

        public function ContextMenuItem(_arg1:String, _arg2:String, _arg3:Object){
            this.m_label = _arg1;
            this.m_action = _arg2;
            this.m_style = _arg3;
            this.draw();
            this.mouseChildren = false;
            this.state = ContextMenuItem.STATE_UP;
        }
        public function get label():String{
            return (this.m_label);
        }
        public function get action():String{
            return (this.m_action);
        }
        public function set state(_arg1:String):void{
            this.m_state = _arg1;
            switch (this.m_state){
                case ContextMenuItem.STATE_UP:
                    this.drawUpState();
                    break;
                case ContextMenuItem.STATE_OVER:
                    this.drawOverState();
                    break;
            };
        }
        public function get state():String{
            return (this.m_state);
        }
        public function draw():void{
            this.drawBg(this.m_style.contextMenuItem.backgroundColor);
            this.drawText(this.m_style.contextMenuItem.color);
        }
        protected function drawBg(_arg1:uint):void{
            if (!this.m_bgShape){
                this.m_bgShape = new Shape();
                this.addChild(this.m_bgShape);
            };
            this.m_bgShape.graphics.clear();
            this.m_bgShape.graphics.beginFill(_arg1);
            this.m_bgShape.graphics.drawRect(0, 0, Math.max(this.m_style.contextMenuItem.width, this.width, (this.parent) ? (this.parent.width - (this.m_style.contextMenu.borderWidth * 2)) : 0), this.m_style.contextMenuItem.height);
        }
        protected function drawText(_arg1:uint):void{
            var _local2:String;
            var _local3:TextFormat;
            var _local4:int;
            if (this.m_label){
                _local2 = this.m_style.contextMenuItem.font;
                _local3 = new TextFormat();
                _local3.align = this.m_style.contextMenuItem.textAlign;
                _local3.color = _arg1;
                _local3.font = _local2;
                _local3.size = this.m_style.contextMenuItem.fontSize;
                if (!this.m_textField){
                    _local4 = this.m_style.contextMenuItem.padding;
                    this.m_textField = new TextField();
                    this.m_textField.embedFonts = true;
                    this.m_textField.defaultTextFormat = _local3;
                    this.m_textField.multiline = false;
                    this.m_textField.antiAliasType = AntiAliasType.ADVANCED;
                    this.m_textField.htmlText = this.m_label;
                    this.m_textField.autoSize = this.m_style.contextMenuItem.textAlign;
                    this.m_textField.selectable = false;
                    this.m_textField.mouseEnabled = false;
                    this.m_textField.width = this.m_textField.textWidth;
                    this.m_textField.height = this.m_textField.textHeight;
                    this.m_textField.x = _local4;
                    this.m_textField.y = ((this.m_style.contextMenuItem.height - this.m_textField.height) >> 1);
                    this.addChild(this.m_textField);
                } else {
                    this.m_textField.defaultTextFormat = _local3;
                    this.m_textField.htmlText = this.m_label;
                };
            };
        }
        protected function drawOverState():void{
            this.drawBg(this.m_style.contextMenuItem.hoverBackgroundColor);
            this.drawText(this.m_style.contextMenuItem.hoverColor);
        }
        protected function drawUpState():void{
            this.drawBg(this.m_style.contextMenuItem.backgroundColor);
            this.drawText(this.m_style.contextMenuItem.color);
        }

    }
}//package Display 
